var app = getApp();
Page({
    data: {
        imgUrls: [
            'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
            'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
            'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
        ],
        indicatorDots: true,
        autoplay: false,
        interval: 5000,
        duration: 1000
    },
    changeIndicatorDots: function(e) {
        this.setData({
            indicatorDots: !this.data.indicatorDots
        })
    },
    changeAutoplay: function(e) {
        this.setData({
            autoplay: !this.data.autoplay
        })
    },
    intervalChange: function(e) {
        this.setData({
            interval: e.detail.value
        })
    },
    durationChange: function(e) {
        this.setData({
            duration: e.detail.value
        })
    },
    onLoad: function (e) {
        var that = this;
        var data1,data2,data3;
        var p1 = new Promise(function(resolve,reject){
            wx.request({
                url: 'http://m.vd.cn/api/tuan/TuanGuide_api', //仅为示例，并非真实的接口地址
                data: {
                    code:"oneyuan"
                },
                method: "POST",
                header: {
                    "Content-Type": "application/x-www-form-urlencoded"  //post
                },
                complete: function( res ) {
                    that.setData( {
                        oneyuandata: res.data.data
                    });
                    if( res == null || res.data == null ) {
                        reject(new Error('网络请求失败'))
                    }
                },
                success: function(res) {
                    if(res.data.code ==0){
                        resolve(res)

                    }
                }
            })
        });

        var p2 = new Promise(function(resolve,reject){
            wx.request({
                url: "http://m.vd.cn/api/tuan/getMemberNumRedis", //仅为示例，并非真实的接口地址
                data: {
                    ids:"100520618_946244",
                    tuanids:"152540"
                },
                method: "POST",
                header: {
                    "Content-Type": "application/x-www-form-urlencoded"  //post
                },
                complete: function( res ) {
                   /* that.setData( {
                        oneyuandata: res.data.data
                    });*/
                    if( res == null || res.data == null ) {
                        reject(new Error('网络请求失败'))
                    }
                },
                success: function(res) {
                    if(res.data.code ==0){
                        resolve(res)

                    }
                }
            })
        });

        var p3 = new Promise(function(resolve,reject){
            wx.request({
                url: "http://m.vd.cn/api/tuan/getRecommend2", //仅为示例，并非真实的接口地址
                data: {
                    prod_id:"100523763_947481"
                },
                method: "POST",
                header: {
                    "Content-Type": "application/x-www-form-urlencoded"  //post
                },
                complete: function( res ) {
                    /* that.setData( {
                     oneyuandata: res.data.data
                     });*/
                    if( res == null || res.data == null ) {
                        reject(new Error('网络请求失败'))
                    }
                },
                success: function(res) {
                    if(res.data.code ==0){
                        resolve(res)

                    }
                }
            })
        });

      Promise.all([p1, p2,p3]).then(function(values) {
             data1 = values[0].data;
             data2 = values[1].data;
             data3 = values[2].data;
             that.setData({    /* 将所有接口的数据传到视图层*/
                  data1 : data1,
                  data2 : data2,
                  data3 : data3
              })
           console.log(values[0].data+values[1].data+values[2].data+"1111");

        });
    }


})